-- Implement query processing as a macro package

# all ?X where ?C ==> transCondition(C, (X, addElement, allAux), NoneFound);
# any of ?X where ?C ==> transCondition(C, (X, chooseElement, anyAux), NoneFound);
 
-- Ptn in Src --> iterate(Src, AuxFun, InitState)
-- where AuxFun looks like:
-- auxF(Ptn,St) is (X,St);
-- auxF(_,S) default is S;
# transCondition( ?Ptn in ?Src, ?Aux, ?Acc, ?Add, ?Init) ==> iterate(Src, auxGen(Ptn, Add, Acc, Aux), Init);

-- C1 and C2
#transCondition(?C1 and ?C2, ?Aux, ?Acc, ?Add, ?Init) ==> 
   transCondition(C1, 

( andGen( transCondition(C2, Aux, #$"init"), #$"init"), Init);

-- Aux function generators

# auxGen(?Ptn, ?Adder, ?Acc, ?Aux) ==> Aux(Ptn,Acc,Adder);

# allAux(?Ptn,?Acc,?Adder) ==> let { #$"auxF"(Ptn,St) is Adder(Acc,St); #$"auxF"(_,St) is St } in #$"auxF";

# anyAux(?Ptn, ?Acc, ?Adder) ==> let { #$"auxF"(Ptn,NoneFound) is NoMore(Acc); #$"auxF"(_,St) is St } in #$"auxF";
